﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.Web.Mvc;

namespace VOD.Models
{
    #region Notice 公告
    public class Notice
    {
        [Key]
        public int NoticeID { get; set; }

        [StringLength(50)]
        [Required(ErrorMessage="*")]
        [DisplayName("标题")]
        public string NoticeTitle { get; set; }

        [StringLength(512)]
        [Required(ErrorMessage = "*")]
        [DisplayName("内容")]
        public string NoticeContent { get; set; }

        [Required(ErrorMessage = "*")]
        [DisplayName("添加时间")]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd hh:mm:ss}")]
        public DateTime AddDate { get; set; }

        [DisplayName("过期时间")]
        [DisplayFormat(ConvertEmptyStringToNull=true,NullDisplayText="无",ApplyFormatInEditMode=true,DataFormatString="{0:yyyy-MM-dd hh:mm:ss}")]
        public DateTime? InvalidDate { get; set; }
    }
    #endregion

    #region Video 视频
    public class Video
    {
        [Key]
        public int VideoID { get; set; }

        [DisplayName("语言")]
        public int LangID { get; set; }

        [DisplayName("地区")]
        public int AreaID { get; set; }

        [DisplayName("视频名称")]
        [StringLength(50,ErrorMessage="长度不得超过50个字符")]
        [Required(ErrorMessage="视频名称 不能为空！")]
        public string Name { get; set; }

        [Display(Name="短标题")]
        [StringLength(7)]
        public string ShortTitle { get; set; }

        [Display(Name = "长标题")]
        [StringLength(14)]
        public string LongTitle { get; set; }

        public int CategoryID { get; set; }

        [DisplayName("导演")]
        [StringLength(50, ErrorMessage = "长度不得超过50个字符")]
        public string Director { get; set; }

        [DisplayName("演员")]
        [StringLength(256, ErrorMessage = "长度不得超过256个字符")]
        public string Actor { get; set; }

        [DisplayName("年份")]
        [StringLength(4, ErrorMessage = "长度不得超过4个字符")]
        [RegularExpression(@"^1[89]\d{2}|^20\d{2}",ErrorMessage="年份不正确")]
        public string ShowYear { get; set; }

        [DisplayName("添加时间")]
        public DateTime? AddDate { get; set; }

        [DisplayName("更新时间")]
        public DateTime? UpdateDate { get; set; }

        [DisplayName("介绍")]
        [DisplayFormat(HtmlEncode=true,ConvertEmptyStringToNull=true,NullDisplayText="无")]
        [StringLength(2048, ErrorMessage = "长度不得超过2048个字符")]
        public string Intro { get; set; }

        [DisplayName("大图推荐")]
        public bool HasBigPic { get; set; }

        [DisplayName("删除到回收站")]
        public int Recycled { get; set; }

        //多部视频对应一种语言
        public virtual VideoLanguage VideoLanguage { get; set; }
        //一部视频对应多种类别
        public virtual ICollection<VideoAndType> VideoAndTypes { get; set; }
        ////一部视频对应一种分类
        public VideoCategory VideoCategory { get; set; }
        //多部视频对应一个区域
        public virtual VideoArea VideoArea { get; set; }
        //一部视频包含多集视频
        public virtual ICollection<VideoUrl> VideoUrls { get; set; }
        //一部视频包含多条评论
        public virtual ICollection<Comment> Comments { get; set; }
        //一部视频对应多条点播记录
        public virtual ICollection<PlayRecord> PlayRecords { get; set; }
    }
    #endregion

    #region VideoUrl 视频路径
    public class VideoUrl
    {
        [Key]
        public int VideoPartID { get; set; }
        public int VideoID { get; set; }
        [StringLength(20)]
        public string Title { get; set; }
        public int VideoOrder { get; set; }
        [StringLength(1024)]
        public string VideoURL { get; set; }

        public DateTime? AddDate { get; set; }

        //多集视频组成一部视频
        public virtual Video Video { get; set; }
        //一部视频对应多条点播记录
        public virtual ICollection<PlayRecord> PlayRecords { get; set; }
    }
    #endregion

    #region VideoLanguage 视频语言
    public class VideoLanguage
    {
        [Key]
        public int LangID { get; set; }
        [Display(Name="语言")]
        public string LangName { get; set; }

        //一种语言包含多部视频
        public virtual ICollection<Video> Videos { get; set; }
    }
    #endregion

    #region VideoAndType 视频与种类集合
    public class VideoAndType
    {
        public int Id { get; set; }
        public int VideoID { get; set; }
        public int TypeID { get; set; }

        //多条记录对应一种类别
        public virtual VideoType VideoType { get; set; }
        //多条记录对应一部视频
        public virtual Video Video { get; set; }
    }
    #endregion

    #region VideoType 视频种类
    public class VideoType
    {
        [Key]
        public int TypeID { get; set; }
        public string TypeName { get; set; }
        public int CategoryID { get; set; }

        //多种类别对应一个分类
        public virtual VideoCategory VideoCategory { get; set; }
    }
    #endregion

    #region VideoCategory 视频分类
    public class VideoCategory
    {
        [Key]
        public int CategoryID { get; set; }
        public string CategoryName { get; set; }

        //一个分类对应多种类别
        public virtual ICollection<VideoType> VideoTypes { get; set; }
        ////一个分类对应多部视频
        public ICollection<Video> Videos { get; set; }
    }
    #endregion

    #region VideoArea 视频区域
    public class VideoArea
    {
        [Key]
        public int AreaID { get; set; }
        [Required(ErrorMessage="*")]
        [Display(Name="地区")]
        public string AreaName { get; set; }

        //一个区域对应多部视频
        public virtual ICollection<Video> Videos { get; set; }
    }
    #endregion

    #region PlayRecord 播放记录
    public class PlayRecord
    {
        [Key]
        [DisplayName("记录ID")]
        public int RecordID { get; set; }

        [DisplayName("用户")]
        public Guid? UserID { get; set; }

        [DisplayName("视频")]
        [Required(ErrorMessage = "视频 不能为空！")]
        public int VideoID { get; set; }

        public int VideoPartID { get; set; }

        [DisplayName("点播时间")]
        public DateTime PlayDate { get; set; }

        //一条记录对应一部视频
        public virtual Video Video { get; set; }
        //一条记录对应一个文件
        public virtual VideoUrl VideoUrl { get; set; }
    }
    #endregion

    #region AD 广告
    public class AD
    {
        [Key]
        [DisplayName("广告ID")]
        public int ADID { get; set; }

        [DisplayName("广告名（对应页面中的id）")]
        [StringLength(50)]
        [Required(ErrorMessage = "广告名 不能为空！")]
        public string ADName { get; set; }

        [DisplayName("广告代码")]
        [StringLength(1024)]
        public string ADScript { get; set; }

        [DisplayName("介绍")]
        [StringLength(400)]
        public string ADIntro { get; set; }
    }
    #endregion

    #region Link 友情链接
    public class Link
    {
        [Key]
        public int LinkID { get; set; }
        [Required(ErrorMessage="*")]
        [StringLength(50)]
        [Display(Name="网站名称")]
        public string LinkName { get; set; }
        [Required(ErrorMessage="*")]
        [StringLength(1024)]
        [Display(Name="网址")]
        public string LinkUrl { get; set; }
        [Display(Name = "添加时间")]
        public DateTime AddDate { get; set; }
    }
    #endregion

    #region SystemLog 系统日志

    public class SystemLog
    {
        [Key]
        public int Id { get; set; }
        [DisplayName("日志描述")]
        public string Description { get; set; }
        [DisplayName("添加时间")]
        public DateTime AddDate { get; set; }
    }

    #endregion

    # region SysConfig 系统配置
    public class SysConfig
    {
        [Key]
        public int ConfigID { get; set; }

        [StringLength(100)]
        [Required(ErrorMessage="*")]
        [DisplayName("网站名称")]
        [DataType(DataType.Text)]
        public string SiteName { get; set; }

        [StringLength(20)]
        [Required(ErrorMessage = "*")]
        [DisplayName("播放器")]
        public string Player { get; set; }

        [StringLength(50)]
        [DisplayName("备案号")]
        public string ICP { get; set; }

        [StringLength(300)]
        [DisplayName("关键字")]
        [DataType(DataType.MultilineText)]
        public string MetaKeyword { get; set; }

        [StringLength(512)]
        [DisplayName("网站描述")]
        [DataType(DataType.MultilineText)]
        public string Description { get; set; }

        [StringLength(1024)]
        [DisplayName("统计代码")]
        [DataType(DataType.MultilineText)]
        [AllowHtml]
        public string CountScript { get; set; }
    }

    #endregion

    #region SiteCount 网站访问量

    public class SiteCount
    {
        [Key]
        public int Id { get; set; }

        [StringLength(128)]
        [Required(ErrorMessage="IP 地址不能为空！")]
        public string IP_Addr { get; set; }
        public DateTime AddDate { get; set; }
    }

    #endregion

    public partial class VODEntities : DbContext
    {
        public DbSet<Notice> Notices { get; set; }
        // 视频相关表
        public DbSet<Video> Videos { get; set; }
        public DbSet<VideoLanguage> VideoLanguages { get; set; }
        public DbSet<VideoAndType> VideoAndTypes { get; set; }
        public DbSet<VideoType> VideoTypes { get; set; }
        public DbSet<VideoCategory> VideoCategories { get; set; }
        public DbSet<VideoArea> VideoAreas { get; set; }
        public DbSet<VideoUrl> VideoUrls { get; set; }
        //用户相关表
        public DbSet<PlayRecord> PlayRecords { get; set; }
        public DbSet<Comment> Comments { get; set; }

        public DbSet<AD> ADs { get; set; }
        public DbSet<Link> Links { get; set; }
        public DbSet<SystemLog> SystemLogs { get; set; }
        public DbSet<SiteCount> SiteCounts { get; set; }
        public DbSet<SysConfig> Sysconfigs { get; set; }
    }
}